﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;

namespace djs_mp3_manager
{
    public class Setting
    {
        static ProgramSettings ps;

        public struct ProgramSettings 
        {
            public string lang;
        }
        
        public static string GetLangSetting()
        {
            return ps.lang;
        }

        public static void Init()
        {
            try
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings();
                XmlReader reader = XmlReader.Create("settings.xml", readerSettings);
                XmlSerializer serializer = new XmlSerializer(typeof(ProgramSettings));
                ps = (ProgramSettings)serializer.Deserialize(reader);
                reader.Close();
            }
            catch (System.Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

        public static void SaveSetting() 
        {
            XmlWriterSettings writerSettings = new XmlWriterSettings();
            //xmlSettings.OmitXmlDeclaration = true;
            writerSettings.Encoding = Encoding.UTF8;
            XmlWriter writer = XmlWriter.Create("settings.xml", writerSettings);
            try
            {
                XmlSerializer xml = new XmlSerializer(typeof(Setting.ProgramSettings));
                ps.lang = "language.xml";
                xml.Serialize(writer, ps);
                writer.Flush();
                writer.Close();

            }
            catch (System.Exception e)
            {
                MessageBox.Show(e.Message);
            }

        }
    }
}
